Skip to content

fix(settings): answer 404 for unknown connection-test run ids - #2841

Open
qiuqianyi66 wants to merge 1 commit into
HKUDS:devfrom
qiuqianyi66:fix/settings-test-run-unknown-id
Open

qiuqianyi66 wants to merge 1 commit into
HKUDS:devfrom
qiuqianyi66:fix/settings-test-run-unknown-id

Conversation

@qiuqianyi66

Copy link
Copy Markdown

What

A connection-test run id the runner no longer knows now answers 404 Unknown test run instead of a 500 with a raw KeyError.

  • ConfigTestRunner.get() returns None for an unknown id instead of raising (dict.get), and cancel() reports False for it — the same shape the memory run manager already uses.
  • GET /api/settings/tests/{service}/{run_id}/events returns 404 before starting the stream when the run is gone.
  • POST /api/settings/tests/{service}/{run_id}/cancel returns 404 when there was nothing to cancel.

Fixes #2840.

Why

Runs live in memory (ConfigTestRunner._runs). A server restart mid-test, or a Settings page reconnecting with an id from the earlier process, asks for a run that is not there. Before:

$ curl -i .../api/settings/tests/llm/nope/events
500 {"detail":"KeyError: 'nope'","type":"KeyError"}

After:

404 {"detail":"Unknown test run"}

Streaming and cancellation for a live run are unchanged. This mirrors GET /api/memory/runs/{run_id}, which already answers 404 unknown run_id via a None lookup.

Tests

Two new files:

  • tests/services/config/test_test_runner_lookup.py — unknown id → None; started run → same object; cancel unknown → False; cancel live → marks cancelled and returns True.
  • tests/api/test_settings_test_run_lookup.py — the events endpoint and the cancel endpoint raise HTTPException(404, "Unknown test run") for an unknown id, and a known run still cancels.

Evidence:

  • new tests fail on the parent commit (5 failed, 2 passed with the old KeyError path) and pass with the change (7 passed);
  • pytest tests/api/test_settings_router.py tests/api/test_settings_service_preview.py tests/services/config -q: 448 passed, plus 6 failures that fail identically on the parent commit in this clone (they need a runtime data/user/settings/agents.yaml that is not part of the repo) and are untouched here;
  • pre-commit run --files ... on the four files: all hooks pass (ruff, ruff-format, detect-secrets, bandit, mypy).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant